﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Game;

namespace Engine
{
    public enum ItemTypes       //Tipos de los Items
    {
        Food,
        Explosive,
        Tool
    }

    public static class ItemList
    {
        public static List<Item>    mItemList;
        public static Texture2D     mItemTexture;

        public static Vector2 Size = new Vector2(128,128);
        public static float Scale = (100/Size.X);

        public static void TextureLoader(Texture2D texture) { mItemTexture = texture; }

        public static void Create()
        {
            mItemList = new List<Item>();

                                   //Sprite                         //Name                              //Type
                                   //Level                          //Damage        //Weight            //Price

            mItemList.Add(new Item(new Rectangle(000,000,128,128),  "Bomb",                             ItemTypes.Explosive, 
                                   1,                               20,             10,                 10));

            mItemList.Add(new Item(new Rectangle(128,000,128,128),  "HandMade Granade",                 ItemTypes.Explosive, 
                                   2,                               25,             15,                 20));

            mItemList.Add(new Item(new Rectangle(256,000,128,128),  "Holy LandMine of Antioch", ItemTypes.Explosive, 
                                   3,                               30,             20,                 30));

            mItemList.Add(new Item(new Rectangle(000,128,128,128),  "One Slice",                        ItemTypes.Food, 
                                   1,                               20,             10,                 10));

            mItemList.Add(new Item(new Rectangle(128,128,128,128),  "Two Slices",                       ItemTypes.Food, 
                                   2,                               25,             15,                 20));

            mItemList.Add(new Item(new Rectangle(256,128,128,128),  "Three Slices",                     ItemTypes.Food, 
                                   3,                               30,             20,                 30));

            mItemList.Add(new Item(new Rectangle(000,256,128,128),  "Adhesive Tape",                    ItemTypes.Tool, 
                                   0,                               0,              10,                 0));
        }

        public static Item GetItem(string name)
        {
            for(byte e=0;e<mItemList.Count;e++)
                if(mItemList[e].Name==name)
                    return mItemList[e];
            return null;
        }

        public static short GetSlot(string name)
        {
            for (byte e = 0; e < mItemList.Count; e++)
                if (mItemList[e].Name == name)
                    return e;
            return -1;
        }

        public static Item GetUpGrade(Item item)
        {
            if (item.Level != 0 && item.Level < 3)
                return mItemList[GetSlot(item.Name) + 1];
            return null;
        }
    }

    public class Item
    {
        #region Variables
        Texture2D   mTexture;
        Rectangle   mRectangle;

        string      mName;
        ItemTypes   mType;

        byte        mLevel;
        byte        mPower;
        byte        mWeight;
        byte        mPrice;
        #endregion Variables

        #region Setters & Getters
        public Texture2D Texture { get { return mTexture; } }
        public Rectangle Rectangle { get { return mRectangle; } }
        
        public string Name
        {
            get { return mName; }
            set { mName = value; }
        }
        public ItemTypes Type
        {
            get { return mType; }
            set { mType = value; }
        }

        public byte Level
        {
            get { return mLevel; }
            set { mLevel = value; }
        }
        public byte Damage
        {
            get { return mPower; }
            set { mPower = value; }
        }
        public byte Weight
        {
            get { return mWeight; }
            set { mWeight = value; }
        }
        public byte Price
        {
            get { return mPrice; }
            set { mPrice = value; }
        }
        #endregion Setters & Getters

        public Item(Rectangle rectangle, string name, ItemTypes type, byte level, byte damage, byte weight, byte price)
        {
            mTexture    = null;
            mRectangle  = rectangle;

            mName       = name;
            mType       = type;

            mLevel      = level;
            mPower     = damage;
            mWeight     = weight;
            mPrice      = price;
        }

        /*
        public void Use(Item i)
        {
            switch(i.mType)
            {
                case ItemTypes.Food:        
                    mLife += i.mPower; 
                break;

                case ItemTypes.Explosive:
                    mTransform.Position = ;
                break;
            }            
        }
        */
    }
}
